import pymysql
class DB:
    def __init__(self):
        self.conn = pymysql.connect(host="127.0.0.1",port=3306,user="root",password="123",
                                    db="p6_1",charset="utf8",cursorclass=pymysql.cursors.DictCursor)
        self.coursor = self.conn.cursor()
    #查找所有
    def findall(self,sql):
        self.coursor.execute(sql)
        return self.coursor.fetchall()
    #查找单个
    def findone(self,sql):
        self.coursor.execute(sql)
        res = self.coursor.fetchone()
        return res
    # 提交
    def insert(self, sql):
        self.coursor.execute(sql)
        self.conn.commit()
    # 关闭
    def close(self):
        self.coursor.close()
        self.conn.close()

db = DB()

